<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;


class Site extends Model
{
   use \App\Models\Traits\ScopeCompanySite;
   use \App\Models\Traits\Site;
    

    
    protected $fillable = [
        'name', 'company_id', 'logo_path', 'lnglat', 'is_default', 'sort_order'
    ];
    
    protected $casts = [
        'lnglat' => 'array',
        'is_default' => 'boolean',
        'company_id'=>'integer',
        'id'=>'integer',
        'value'=>'integer',
    ];
    
    public function getCompanyField() {
        return 'company_id';
    }
    
    public function getSiteField() {
        return 'id';
    }
    
    //项目信息
    public function project() {
        return $this->belongsTo('App\Models\Company', "company_id", "Co_ID");
    }
    
        //经纬度
    public function setLnglatAttribute($value)
    {
        if ($value) {
            $this->attributes['lnglat'] = json_encode($value);
        }
    }
    
    //视频设备
    public function videos() {
        return $this->hasMany('App\Models\PriDeviceInfo', "AreaId", "id");
    }
}
